﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.Extensions.DependencyInjection;

using Xc.DataAccess.HyperTerminalCore.Services;

namespace Microsoft.Extensions.DependencyInjection
{
    public static class ApplicationExtension
    {
        /// <summary>
        /// 添加TCP套接字服务 
        /// 注入服务列表
        /// <list type="number">
        /// <item><term>TCP服务端工厂</term><see cref="ITcpServerFactory"/></item>
        /// <item><term>TCP服务端服务</term><see cref="ITcpServerService"/></item>
        /// <item><term>TCP客户端服务</term><see cref="ITcpClientService"/></item>
        /// <item><term>TCP客户端端工厂</term><see cref="ITcpClientFactory"/></item>
        /// <item><term>UDP服务端工厂</term><see cref="IUdpServerFactory"/></item>
        /// <item><term>UDP服务端</term><see cref="IUdpServerService"/></item>
        /// </list>
        /// </summary>
        /// <param name="serviceDescriptors"></param>
        /// <returns></returns>
        public static IServiceCollection AddSocketService(this IServiceCollection serviceDescriptors)
        {
            serviceDescriptors.AddSingleton<ITcpServerFactory, TcpServerFactory>();
            serviceDescriptors.AddTransient<ITcpServerService, TcpServerService>();
            serviceDescriptors.AddTransient<ITcpClientService, TcpClientService>();
            serviceDescriptors.AddSingleton<ITcpClientFactory, TcpClientFactory>();
            serviceDescriptors.AddTransient<IUdpServerService, UdpServerService>();
            serviceDescriptors.AddSingleton<IUdpServerFactory, UdpServerFactory>();
            return serviceDescriptors;
        }
    }
}
